/*
 * Copyright (c) sl All rights reserved.
 * 本软件源代码版权归sl所有,未经许可不得任意复制与传播.
 */
package com.sl.crawler.manager;

import com.sl.crawler.common.enums.EmYn;
import com.sl.crawler.dao.XiaoquDao;
import com.sl.crawler.dao.base.BaseDao;
import com.sl.crawler.domain.Xiaoqu;
import com.sl.crawler.manager.base.BaseManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author sl
 */
@Service
public class XiaoquManager extends BaseManager<Xiaoqu, Long> {
    @Autowired
    private XiaoquDao xiaoquDao;
    @Autowired
    private XiaoquDetailDayManager xiaoquDetailDayManager;

    public BaseDao<Xiaoqu, Long> getDao() {
        return xiaoquDao;
    }

    //自定义扩展
    public void saveOrUpdateXiaoquAndDetail(Xiaoqu xiaoqu) {
        this.saveOrUpdateXiaoqu(xiaoqu);
        xiaoquDetailDayManager.saveOrUpdateXiaoquDetailDay(xiaoqu);
    }

    public void saveOrUpdateXiaoqu(Xiaoqu xiaoqu) {
        Xiaoqu xiaoquParam = new Xiaoqu();
        xiaoquParam.setXiaoquId(xiaoqu.getXiaoquId());
        xiaoquParam.setYn(EmYn.YES.value());
        Xiaoqu xiaoquDb = this.selectOneEntry(xiaoquParam);
        if (xiaoquDb == null || xiaoquDb.getId() == null) {
            this.insertEntry(xiaoqu);
        } else {
            xiaoqu.setId(xiaoquDb.getId());
            this.updateByKey(xiaoqu);
        }
    }
}